<?php
	class MovDAO{
		protected $db;

		public function __construct ($db){
			$this->db = $db;
		}

		public function setDb($db){
			$this->db = $db;
		}

		public function getDb(){
			return $this->db;
		}

		public function addMov($m){		
			$sql = "insert into mov (descr, dt)
					values('{$m->getDescr()}',null)";		
			$res = $this->getDb()->insert($sql);			
			return $res;
		}
		
		public function getMov($id){
			$sql = "select MOV, DESCR, DT
					from mov
					where mov = {$id}";
			$res = $this->getDb()->query($sql);		
			if($res[0]){
				$r = $res[0];
				$m = new Mov($r['MOV'],$r['DESCR'],$r['DT']);
			}
			return $m;
		}

		public function getLista($where=array()){
			$where = ($where ? "where ".implode(" and ",$where) : "");
			$lista = array();

			$sql = "select m.MOV, m.DESCR, m.DT
					from mov m
					join mov_ms mm on mm.MOV = m.MOV
					$where
					group by m.MOV, m.DESCR, m.DT
					order by m.dt";
			
			$res = $this->getDb()->query($sql);		
			if($res){
				foreach($res as $r){
					$lista[] = new Mov($r['MOV'],$r['DESCR'],$r['DT']);
				}
			}
			return $lista;
		}

		public function delMsMov($m){
		}
	}
?>